using System;
using System.Globalization;
using System.Windows.Data;

namespace DeepmixRadioClient.Workflow
{
    public class TimeSpaneConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null) return null;
            if(value is TimeSpan)
            {
                var timeSpan = (TimeSpan)value;
                var mins = timeSpan.Minutes.ToString(CultureInfo.InvariantCulture);
                if (mins.Length == 1) mins = "0" + mins;

                var hs = timeSpan.Hours.ToString(CultureInfo.InvariantCulture);
                if (hs.Length == 1) hs = "0" + hs;
                return string.Format("{0}:{1}", hs, mins);
            }
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }
}